﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARR.Entities;
using System.Collections.ObjectModel;
using ARR.UI.HistoryService;

namespace ARR.UI.Models
{
    
    public interface IHistoryGenerationModel : IModelBase
    {
        List<HistoryDetail> History { get; set; }
        
        void GenerateHistory();
    }


    public class HistoryGenerationModel : ModelBase, IHistoryGenerationModel
    {
        public HistoryGenerationModel()
        {
            History = new List<HistoryDetail>();
            
            LoadHistory();
        }

        public List<HistoryDetail> History { get; set; }
        
        private void LoadHistory()
        {
            HistoryServiceClient service = new HistoryServiceClient();

            try
            {
                History = service.GetCurrentRangeReviewHistory(WorkspaceData.Instance.RangeReview.Id);
                service.Close();
            }
            catch
            {
                service.Abort();
                throw;
            }
        }

        public void GenerateHistory()
        {
            HistoryServiceClient service = new HistoryServiceClient();

            try
            {
                service.GenerateHistory(WorkspaceData.Instance.RangeReview.Id);
                service.Close();
            }
            catch
            {
                service.Abort();
                throw;
            }
        }
    }


    public class HistoryGenerationModelMock : MockModelBase, IHistoryGenerationModel
    {
        public HistoryGenerationModelMock()
        {

        }

        public List<HistoryDetail> History
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public void GenerateHistory()
        {
            throw new NotImplementedException();
        }
    }
}
